package ltd.flython.dlock.context;

import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.stereotype.Component;

import java.net.InetAddress;
import java.net.UnknownHostException;

@Component
//@ConditionalOnMissingBean(value = HostIdentitySupplier.class)
public class SingleHostIdentitySupplier implements HostIdentitySupplier {
    String hostName;

    public SingleHostIdentitySupplier() {
        try {
            InetAddress localHost = InetAddress.getLocalHost();
            hostName = localHost.getHostName();
        } catch (UnknownHostException e) {
            hostName = "alone";
        }
    }

    @Override
    public String get() {
        return hostName;
    }
}
